home *** CD-ROM | disk | FTP | other *** search
Text File | 1988-08-18 | 11.3 KB | 576 lines | [TEXT/MACH] |
- \ notification manager example
- \ JL 15.8.88
-
- only forth definitions
- also assembler also mac also i/o
- decimal
-
- \ structure of a NM record
-
- 0 CONSTANT qLink \ pointer
- 4 CONSTANT qType \ integer
- 6 CONSTANT nmFlags \ integer
- 8 CONSTANT nmPrivate \ longint
- 12 CONSTANT nmReserved \ integer
- 14 CONSTANT nmMark \ integer
- 16 CONSTANT nmSIcon \ handle
- 20 CONSTANT nmSound \ handle
- 24 CONSTANT nmStr \ StringPtr
- 28 CONSTANT nmResp \ ProcPtr
- 32 CONSTANT nmRefCon \ longint
-
- 8 CONSTANT nmType
-
- .TRAP _NMInstall $A05E
- .TRAP _NMRemove $A05F
-
- CODE NMInstall ( NMRec -- result )
- MOVE.L (A6)+,A0
- _NMInstall
- MOVE.L D0,-(A6)
- RTS
- END-CODE MACH
-
- CODE NMRemove ( NMRec -- result )
- MOVE.L (A6)+,A0
- _NMRemove
- MOVE.L D0,-(A6)
- RTS
- END-CODE MACH
-
- $5E CONSTANT nmTrap#
- $9F CONSTANT unkTrap#
-
- variable myNMRec 32 vallot
- variable nmPresent \ for checking whether the NM is implemented
- variable nmChanged \ flag for telling supervisor task
- \ that something has changed
- variable nmSecs \ time in seconds for next notify alert
-
- : notify-request
- { mark SIcon sound str resp refCon | --
- nmPtr result }
-
- nmType mynmRec qType + w!
- mark mynmRec nmMark + w!
- SIcon mynmRec nmSIcon + !
- sound mynmRec nmSound + !
- str mynmRec nmStr + !
- resp mynmRec nmResp + !
- refCon mynmRec nmRefCon + !
-
- mynmRec dup NMInstall
- ;
-
- 300 CONSTANT AppleID
- 301 CONSTANT FileID
- 302 CONSTANT EditID
-
- 2000 CONSTANT updID
- 2001 CONSTANT msgID
-
- 110 CONSTANT wVisible \ offset into window record
-
- 132 USER modelessVector
- 60 USER fID
-
- CREATE APPLESTRING $01 C, $14 C,
-
- NEW.WINDOW nmWindow
-
- " NM" nmWindow TITLE
- 1 1 16 16 nmWindow BOUNDS
- Plain Visible NoCloseBox NoGrowBox nmWindow ITEMS
-
- 600 4000 TERMINAL nmTask
-
- NEW.MBAR nmBar
-
- NEW.MENU AppleMenu
- APPLESTRING AppleMenu TITLE
- 0 APPLEID AppleMenu BOUNDS
- " About Appointments ...;(-" AppleMenu ITEMS
-
- NEW.MENU FileMenu
- " File" FileMenu TITLE
- 0 FileID FileMenu BOUNDS
- " Close;Quit" FileMenu ITEMS
-
- NEW.MENU EditMenu
- " Edit" EditMenu TITLE
- 0 EditID EditMenu BOUNDS
- " (Undo/Z;(-;Cut/K;Copy/C;Paste/V;Clear" EditMenu ITEMS
-
- VARIABLE DAName 60 VALLOT
- VARIABLE updStore 160 VALLOT \ for 'update appointments' dialog
- VARIABLE msgStore 160 VALLOT \ for 'edit message' dialog
- VARIABLE updPtr
- VARIABLE msgPtr \ for storing the dialog pointers
- VARIABLE updRect 4 vallot
- VARIABLE hUpdList \ stores list handle
- VARIABLE listRows \ total # of rows in list
- VARIABLE datim 10 VALLOT \ 14 bytes for date-time record
- VARIABLE msgTxt 252 VALLOT \ 256 bytes for item text
-
- \ ***** list manager support
-
- \ List Manager select flags.
- 128 CONSTANT OnlyOne
- 64 CONSTANT ExtendDrag
- 32 CONSTANT NoDisjoint
- 16 CONSTANT NoExtend
- 8 CONSTANT NoRect
- 4 CONSTANT UseSense
- 2 CONSTANT NoNilHilite
-
- \ Offsets into the List record
- 12 CONSTANT IndentOffset
- 36 CONSTANT SelFlags
- 80 CONSTANT LDataHandle
-
- CREATE ArrayDim \ Initially we will have an empty array.
- \ We'll add rows and columns later.
- 0 W, \ Row-o.
- 0 W, \ Column-o.
- 0 W, \ Row-i.
- 1 W, \ Column-i.
-
- : NewVList ( rview databounds size wPtr - lhandle )
- 0 \ LDEF proc id
- swap \ window pointer
- 0 \ DrawIt flag
- 0 \ HasGrow flag
- 0 \ scrollHoriz flag
- -1 \ scrollVert flag
- (CALL) LNew
- ;
-
- : MakeList { rect vcell hcell wPtr |
- lhandle cellpt rectbr recttl -- lhandle }
- rect @ $10001 + -> recttl
- rect 4 + @ $10010 - -> rectbr
- ^ recttl \ Pass rectangle.
- ArrayDim \ Pass bounds.
- vCell ^ cellpt W!
- hCell ^ cellpt 2+ W!
- cellpt \ Pass cell size.
- wPtr
- NewVList -> lhandle
-
- OnlyOne NoNilHilite + \ Select only one cell at a time.
- lhandle @ SelFlags + C! \ Don't hilite empty cells.
- lhandle
- ;
-
- : read1line { ^pfile string | pStr char -- flag }
- string -> pStr
- BEGIN
- ^pfile @ virtual c@ -> char
- 1 ^pfile +!
- char 0= char 13 = OR 0= WHILE
- 1 +> pStr
- char pStr c!
- REPEAT
- pStr string - string c!
- char
- ;
-
- : open-dates-file
- " Dates" $open dup 0<
- IF drop " Dates" dup
- $create drop
- $open
- THEN
- fID w!
- ;
-
- : fill-list { | pfile theCell -- }
- 0 listRows !
- open-dates-file
- 0 -> pfile
- BEGIN
- ^ pfile msgTxt read1line WHILE
- 1 listRows @ hupdList @ call LAddRow drop
- 0 -> theCell
- listRows @ ^ theCell w!
- 1 listRows +!
- msgtxt count theCell hupdList @ call LSetCell
- REPEAT
- fID w@ closefile
- -1 hUpdList @ call LDoDraw
- hupdList @ call LAutoScroll
- ;
-
- : write-list { | len theCell offset -- }
- open-dates-file
- 0 -> offset
- listRows @ 0 DO
- 0 -> theCell i ^ theCell w!
- 0 -> len 255 ^ len w!
- msgTxt ^ len theCell hUpdList @
- call LGetCell
- ^ len w@ -> len
- 13 msgTxt len + c!
- 1 +> len
- offset len msgTxt fID w@ write
- len +> offset
- LOOP
- 0 msgtxt c!
- offset 1 msgTxt fID w@ write
- offset 1+ fID w@ setEOF
- fID w@ closefile
- ;
-
- \ UserDraw procedure
- \ must use (call) instead of call and use glue code
- \ for saving registers and setting up Forth stack
-
- : UserDraw { theDlg theItem | iType iHdl rectbr recttl -- }
-
- theDlg theItem ^ iType ^ iHdl ^ recttl
- (call) GetDItem
- ^ recttl (call) FrameRect
- theDlg 24 + @ \ visRgn of dialog window
- hUpdList @ \ list handle
- (call) LUpdate
- ;
-
- \ UserDraw procedure glue code
- \ sets up local stack etc.
-
- CODE gUser
- LINK A6,#-512 ( 512 bytes of local Forth stack )
- MOVEM.L A0-A5/D0-D7,-(A7) ( save registers )
- MOVE.L A6,A3 ( setup local loop return stack )
- SUBA.L #256,A3 ( in the low 256 local stack bytes )
- CLR.L D1
- MOVE.W 8(A6),D1 ( theItem )
- MOVE.L 10(A6),D0 ( theDialog )
- MOVE.L D0,-(A6)
- MOVE.L D1,-(A6)
-
- UserDraw
-
- MOVEM.L (A7)+,A0-A5/D0-D7 ( restore registers )
- UNLK A6
- MOVE.L (A7)+,A0 ( return address )
- ADD.W #6,A7 ( pop off 6 bytes of parameters )
- JMP (A0)
- RTS
- END-CODE MACH
-
- : update-cell { string | theCell -- }
- 0 -> theCell
- -1 ^ theCell hupdList @ call LGetSelect
- IF
- string count theCell hupdList @
- call LSetCell
- THEN
- ;
-
- : getText { dlgPtr item# string | iType iHdl iBox -- string }
- dlgPtr item# ^ iType ^ iHdl ^ iBox
- call GetDItem
- iHdl string call GetIText
- string
- ;
-
- : setText { dlgPtr item# string | iType iHdl iBox -- }
- dlgPtr item# ^ iType ^ iHdl ^ iBox
- call GetDItem
- iHdl string call SetIText
- ;
-
- : setup-msg { editDlg string | -- string }
- editDlg 8 string getText ( year )
- editDlg 9 string 3 + getText ( month )
- editDlg 10 string 6 + getText ( day )
- editDlg 11 string 9 + getText ( hour )
- editDlg 12 string 12 + getText ( min )
- editDlg 13 string 15 + getText ( sec )
-
- editDlg 3 string 18 + getText ( message )
- c@ 18 + string c!
-
- ascii / dup string 3 + c! string 6 + c!
- 32 string 9 + c! 32 string 18 + c!
- ascii : dup string 12 + c! string 15 + c!
- string
- ;
-
- : parse-msg { string | sPtr -- }
- string c@ 18 - string 18 + c!
- 6 0 do
- string i 3 * + -> sPtr
- 2 sPtr c!
- sPtr call stringtonum
- datim i 2* + w!
- loop
- datim w@ 1900 + datim w!
- ;
-
- : set-dlg { editDlg string | -- }
- editDlg 8 string setText ( year )
- editDlg 9 string 3 + setText ( month )
- editDlg 10 string 6 + setText ( day )
- editDlg 11 string 9 + setText ( hour )
- editDlg 12 string 12 + setText ( min )
- editDlg 13 string 15 + setText ( sec )
- editDlg 3 string 18 + setText ( message )
- ;
-
- : getMsg { text | editDlg itemHit iTyp iHdl iBox
- -- string_or_zero }
- msgID 0 -1 call GetNewDialog -> editDlg
- text parse-msg
- editDlg text set-dlg
- 0 ^ itemHit call ModalDialog
- ^ itemHit w@ CASE
- 1 OF editDlg msgTxt setup-msg ENDOF
- 2 OF ( Cancel ) 0 ENDOF
- ENDCASE
- editDlg call DisposDialog
- ;
-
- : userEdit { | theCell len -- }
- 0 -> theCell
- -1 ^ theCell hupdList @ call LGetSelect
- IF
- 255 ^ len w!
- msgTxt 1+ ^ len theCell hupdList @ call LGetCell
- ^ len w@ msgtxt c!
- msgtxt getMsg ?dup IF
- update-cell
- THEN
- THEN
- nmChanged on
- ;
-
- : userAdd { | theCell -- }
- " yy/mm/dd hh:mm:ss Your message - "
- dup c@ 1+ msgtxt swap cmove
- msgtxt getMsg IF
- 0 -> theCell
- -1 ^ theCell hupdList @ call LGetSelect
- IF 0 theCell hUpdList @ call LSetSelect THEN
- 1 listRows @ hupdList @ call LAddRow
- 0 -> theCell
- listRows @ ^ theCell w!
- 1 listRows +!
- msgtxt count theCell hupdList @ call LSetCell
- -1 theCell hUpdList @ call LSetSelect
- hupdList @ call LAutoScroll
- THEN
- nmChanged on
- ;
-
- : userDelete { | theCell -- }
- 0 -> theCell
- -1 ^ theCell hupdList @ call LGetSelect
- IF
- 1 ^ theCell w@ hupdList @ call LDelRow
- -1 listRows +!
- THEN
- nmChanged on
- ;
-
- : userList-handler { | thePt thePort -- }
- ^ thePort call getPort
- call frontwindow call setport
- ^ thePt call getMouse
- thePt event-record modifiers + w@
- hUpdList @
- call LClick
- IF ( double click ) userEdit THEN
- thePort call setPort
- ;
-
- : CloseMe
- updPtr @ call CloseDialog
- ;
-
- : QuitMe CloseMe ;
-
- : dialog-handler
- { itemHit dlgPtr | -- }
-
- itemHit CASE
- 1 OF CloseMe ENDOF
- 2 OF userEdit ENDOF
- 3 OF userAdd ENDOF
- 4 OF userDelete ENDOF
-
- 5 OF userList-handler ENDOF
- ENDCASE
- ;
-
- : installupdPtr
- updPtr @ ?dup IF
- nmTask @ 2+ call SetWRefCon
- ELSE
- cr ." Couldn't create dialog"
- ABORT
- THEN
- ;
-
- : installuserDraw { pUser | iType iHdl rectbr recttl -- }
- updPtr @ 5 ^ iType ^ iHdl ^ recttl
- call GetDItem
- updPtr @ 5 ^ iType w@ pUser ^ recttl
- call SetDItem
- ^ recttl 16 280 updPtr @ MakeList
- hUpdList !
- ;
-
- : UndoMe ;
- : CutMe ;
- : CopyMe ;
- : PasteMe ;
- : ClearMe ;
-
- : do-about
- 128 0 CALL Alert DROP
- ;
-
- : do-apple { item# }
- \ item# = 1 (About...)?
- item# 1 =
- IF do-about
- ELSE
- Applemenu @ item# DAName CALL GetItem
- DAName CALL OpenDeskAcc DROP
- THEN ;
-
- : DO-FILE ( item# - ) ( handles selections from the file menu )
- CASE
- 1 OF CloseMe ENDOF
- 2 OF QuitMe ENDOF
- ENDCASE
- ;
-
- : DO-EDIT ( item# - ) ( handles selections from the edit menu )
- dup 1- call SysEdit ( item# flag )
- 0= IF
- CASE
- 1 OF UndoMe ENDOF
- 3 OF CutMe ENDOF
- 4 OF CopyMe ENDOF
- 5 OF PasteMe ENDOF
- 6 OF ClearMe ENDOF
- ENDCASE
- THEN
- ;
-
- : nmBAR-handler ( item# menuID - )
- CASE
- APPLEID OF DO-APPLE ENDOF
- FILEID OF DO-FILE ENDOF
- EDITID OF DO-EDIT ENDOF
- ENDCASE
- 0 CALL HILITEMENU
- ;
-
- : say_it
- nmPresent @ IF
- 1 ( mark )
- 0 ( no Icon )
- -1 ( system beep )
- msgTxt 18 + ( string to display )
- -1 ( remove request )
- 0 ( no refCon )
- notify-request
- 2drop
- ELSE
- 5 call sysbeep
- THEN
- ;
-
- : get_time { | time -- secs }
- ^ time call readdatetime drop @
- ;
-
- : get_next_date { | len theCell secs -- }
- listRows @ 0 DO
- 0 -> theCell i ^ theCell w!
- 255 ^ len w!
- msgTxt 1+ ^ len theCell hupdList @ call LGetCell
- ^ len w@ msgtxt c!
- msgtxt parse-msg
- datim call date2secs -> secs
- get_time secs u< IF leave THEN
- -1 -> secs \ in case no date matches
- LOOP
- secs nmSecs !
- nmChanged off
- ;
-
- : wait { ticks | time -- }
- call tickcount ticks + -> time
- begin
- pause
- call tickcount time >
- until
- ;
-
- : check_next_date
- nmChanged @ IF get_next_date THEN
- nmSecs @ get_time
- u< IF
- say_it
- 60 wait
- nmChanged on
- THEN
- ;
-
- : check_dialog_up
- updPtr @ wVisible + c@
- 0= IF write-list bye
- THEN
- ;
-
- : go.nm
- ACTIVATE
- fill-list
- ['] dialog-handler modelessVector !
- ['] nmBar-handler menu-vector !
- nmWindow dup call showWindow
- call selectWindow
- updPtr @ dup call showWindow
- call selectWindow
- call DrawMenuBar
- begin
- PAUSE
- check_next_date
- check_dialog_up
- again
- ;
-
- : nmPresent?
- NMTrap# CALL GetTrapAddress
- UnkTrap# CALL GetTrapAddress
- = IF 0 ELSE 1 THEN
- nmPresent !
- ;
-
- : start
- nmPresent?
- nmWindow ADD
- nmWindow nmTask BUILD
-
- nmBar ADD
- nmBar AppleMenu ADD
- AppleMenu @ ascii DRVR CALL AddResMenu
- nmBar FileMenu ADD
- nmBar EditMenu ADD
- nmBar nmTask mbar>task
-
- updID updStore -1 call GetNewDialog
- updPtr !
-
- installupdPtr
- ['] gUser installUserDraw
-
- nmChanged on
- nmTask go.nm
- ;
-